﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordNet.Core;
using WordNet.Core.ElementContracts;
using WordNet.Core.DataContract;

namespace WordNet.CoreTests.Parsers
{
    [TestClass]
    public class UnitTestIndexLineAdverb:UnitTestBase
    {
        const string ADVERB_LINE = @"abaxially r 1 2 ! \ 1 0 00515646";
        
        [ClassInitialize]
        public static void ClassInit(TestContext context)
        {
            Container = MEFLoader.Load();
        }
        
        [TestMethod]
        public void CanParseAdverb()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(ADVERB_LINE);
            Assert.IsNotNull(indexWord);
        }

        [TestMethod]
        public void CanParseLemmaAdverb()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(ADVERB_LINE);
            Assert.IsNotNull(indexWord);
            string expectedLemma = "abaxially";
            Assert.AreEqual(expectedLemma, indexWord.Lemma);
        }

        [TestMethod]
        public void CanParseSyntacticCategoryAdverb()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(ADVERB_LINE);
            Assert.IsNotNull(indexWord);
            POS expectedPOS = POS.ADVERB;

            Assert.AreEqual(expectedPOS, indexWord.PartOfSpeech);
        }

        [TestMethod]
        public void CanParsePointersAdverb()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(ADVERB_LINE);
            Assert.IsNotNull(indexWord);
            int expected_pointer_count = 2;
            Assert.AreEqual(expected_pointer_count, indexWord.GetPointers().Count);
            Assert.IsTrue(indexWord.GetPointers().Contains(Pointer.GetPointerType("!", POS.ADVERB)));
            Assert.IsTrue(indexWord.GetPointers().Contains(Pointer.GetPointerType(@"\", POS.ADVERB)));


            Assert.IsFalse(indexWord.GetPointers().Contains(Pointer.GetPointerType("#s", POS.ADVERB)));
        }

        [TestMethod]
        public void CanParseTagSenseCountAdverb()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(ADVERB_LINE);
            int expectedTagSenseCount = 0;
            Assert.AreEqual(expectedTagSenseCount, indexWord.TagSenseCount);
        }

        [TestMethod]
        public void CanParseSynsetOffsetAdverb()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(ADVERB_LINE);
            int expectedOffsetCount = 1;
            Assert.AreEqual(expectedOffsetCount, indexWord.GetWordIDs().Count);
            foreach (var wordId in indexWord.GetWordIDs())
            {
                Assert.AreEqual("abaxially", wordId.Lemma);
                Assert.AreEqual(POS.ADVERB, wordId.PartOfSpeech);
            }
            Assert.AreEqual(int.Parse("00515646"), indexWord.GetWordIDs()[0].SynsetID.Offset);
            Assert.AreEqual(POS.ADVERB, indexWord.GetWordIDs()[0].SynsetID.PartOfSpeech);
        }
    }
}
